<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title>注册信息</title>
<script type="text/javascript">
	function addUser() {
	var contactTelField = document.getElementById("telphone");
		if ((contactTelField.value) != "") {
			
			for (var i=0; i<contactTelField.value.length; i++) {
				var c = contactTelField.value.charAt(i);
				if (!(c >= '0' && c <= '9')) {
					alert("电话号码不合法！");
					contactTelField.focus();
					return false;
				}
			}
		}else{
			alert("电话号码不能为空！");
			contactTelField.focus();
		    return false; 
		}
	
				//密码至少6位
		if (document.getElementById("password").value.length < 6) {
			alert("餐馆密码至少6位！,当前为"+document.getElementById("password").value.length);
			document.getElementById("password").focus();
			return false;
		}
		//餐馆地址不为空
		if (document.getElementById("address").value=="") {
			alert("地址不为空");
			document.getElementById("address").focus();
			return false;
		}
		//餐馆收入只能是数字
	
		if ((document.getElementById("sale").value) != "") {
			
			for (var i=0; i<document.getElementById("sale").value.length; i++) {
				var c = document.getElementById("sale").value.charAt(i);
				if (!(c >= '0' && c <= '9')) {
					alert("餐馆收入不合法，必须为数字！");
					document.getElementById("sale").focus();
					return false;
				}
			}
	}
	else{
	   alert("收入不能为空");
	   document.getElementById("sale").focus();
	   return false;
	}
	//餐馆介绍不能为空
	if (document.getElementById("remark").value=="") {
			alert("餐馆介绍不为空");
			document.getElementById("remark").focus();
			return false;
		}
			
}
var xmlHttp;
	 
	function createXMLHttpRequest() {
		//表示当前浏览器不是ie,如ns,firefox
		if(window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	function validate(field) {
		//alert(document.getElementById("userId").value;
		//alert(field.value);
			//创建Ajax核心对象XMLHttpRequest
			createXMLHttpRequest();
			
			var url = "RestNameVal?userName=" + field.value + "&time=" + new Date().getTime();
			
			//设置请求方式为GET，设置请求的URL，设置为异步提交
			xmlHttp.open("GET", url, true);
			
			//将方法地址复制给onreadystatechange属性
			//类似于电话号码
			xmlHttp.onreadystatechange=callback;
			
			//将设置信息发送到Ajax引擎
			xmlHttp.send(null);
	}

	function callback() {
		
		//Ajax引擎状态为成功
		if (xmlHttp.readyState == 4) {
			//HTTP协议状态为成功
			
			if (xmlHttp.status == 200) {
				if (xmlHttp.responseText != "") {
					//alert(xmlHttp.responseText);
					document.getElementById("spanUserId").innerHTML = "<font color='red' size='2' >" + xmlHttp.responseText + "</font>"
				}else {
					document.getElementById("spanUserId").innerHTML = "";
				}
			}else {
				alert("请求失败，错误码=" + xmlHttp.status);
			}
		}
	}
</script>

<link rel="stylesheet" type="text/css" href="css/li.css">

</head>
<center>
<body bgcolor="#FFCCFF">
<form action="OperatorResistCtrl" method="post" onSubmit="return addUser()">
<table width="240" border="0">
  <tr>
    <td class="li">餐馆名称：</td>
    <td><input name="userName" type="text" id="userName" onblur="validate(this)"></br><span id="spanUserId"></span></td>
  </tr>
  <tr>
    <td nowrap="nowrap" class="li">餐馆密码：</td>
    <td><input type="password" name="password" /></td>
  </tr>
  <tr>
    <td class="li">餐馆电话</td>
    <td><input type="text" name="telphone" /></td>
  </tr>
  <tr>
    <td class="li">餐馆地址：</td>
    <td><input type="text" name="address" /></td>
  </tr>
  <tr>
    <td class="li">餐馆收入：</td>
    <td><input type="text" name="sale" /></td>
  </tr>
  <tr>
    <td class="li">餐馆介绍：</td>
    <td><input type="text" name="remark" /></td>
  </tr>
  <tr>
    <td class="li">菜系&nbsp;&nbsp;ID</td>
    <td><select name="id">
  <option value="1">1</option>
  <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5">5</option>
   <option value="6">6</option>
   <option value="7">7</option>
   <option value="8">8</option>  
  </select></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>  <input type="submit" value="登录" onClick="addUser()"></td>
  </tr>
</table>
<font size="+1" color=""></font>
</form>
</body></center>
</html>
